<?php
namespace app\common\model;

class ShopJicaiGoodsModel extends BaseModel
{
    protected $name = 'shop_jicai_goods';
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改

    /*修改器*/
    protected function getJicaiStatusTextAttr($value, $data)
    {
        $status = [0=>'审核中',1=>'正常',2=>'结束'];
        return $status[$data['jicai_status']];
    }
    protected function getProgressAttr($value, $data)
    {
        $progress = round($data['jicai_sale']/$data['jicai_stock']*100,0);
        return $progress.'%';
    }

    /**
     * 店铺商品价格
     * @param $value
     * @param $data
     * @return mixed
     */
    protected function getSimplePriceAttr($value, $data)
    {
        $goodsSkuModel = new ShopGoodsSkuModel();
        $goodsPrice = $goodsSkuModel->where('sku_id',$data['sku_id'])->value('goods_price');
        $goodsPrice = format_goods_price($goodsPrice);
        return $goodsPrice['simple_price'];
    }
}
